package com.atguigu.day07;

import com.atguigu.beans.WaterSensor;
import com.atguigu.func.WaterSensorMapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/4/8
 * 该案例演示了处理函数的分类
 */
public class Flink03_ProcessFunction {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<String> socketDS = env.socketTextStream("hadoop102", 8888);
        SingleOutputStreamOperator<WaterSensor> wsDS = socketDS.map(new WaterSensorMapFunction());

        /*
        wsDS.process(
                new ProcessFunction<WaterSensor, WaterSensor>() {
                    @Override
                    public void processElement(WaterSensor value, ProcessFunction<WaterSensor, WaterSensor>.Context ctx, Collector<WaterSensor> out) throws Exception {

                    }
                }
        )
        wsDS.process(
                new ProcessFunction<WaterSensor, WaterSensor>() {
                    @Override
                    public void processElement(WaterSensor value, ProcessFunction<WaterSensor, WaterSensor>.Context ctx, Collector<WaterSensor> out) throws Exception {

                    }
                }
        )
        wsDS.keyBy(WaterSensor::getId).process(
                new KeyedProcessFunction<String, WaterSensor, String>() {
                    @Override
                    public void processElement(WaterSensor value, KeyedProcessFunction<String, WaterSensor, String>.Context ctx, Collector<String> out) throws Exception {

                    }
                }
        )
        wsDS
                .keyBy(WaterSensor::getId)
                .window(TumblingEventTimeWindows.of(Time.seconds(10)))
                .process(
                        new ProcessWindowFunction<WaterSensor, WaterSensor, String, TimeWindow>() {
                            @Override
                            public void process(String s, ProcessWindowFunction<WaterSensor, WaterSensor, String, TimeWindow>.Context context, Iterable<WaterSensor> elements, Collector<WaterSensor> out) throws Exception {

                            }
                        }
                )

        wsDS
                .windowAll(TumblingEventTimeWindows.of(Time.seconds(10)))
                .process(
                        new ProcessAllWindowFunction<WaterSensor, WaterSensor, TimeWindow>() {
                            @Override
                            public void process(ProcessAllWindowFunction<WaterSensor, WaterSensor, TimeWindow>.Context context, Iterable<WaterSensor> elements, Collector<WaterSensor> out) throws Exception {

                            }
                        }
                )

        wsDS
                .connect(wsDS)
                .process(
                        new CoProcessFunction<WaterSensor, WaterSensor, String>() {
                            @Override
                            public void processElement1(WaterSensor value, CoProcessFunction<WaterSensor, WaterSensor, String>.Context ctx, Collector<String> out) throws Exception {

                            }

                            @Override
                            public void processElement2(WaterSensor value, CoProcessFunction<WaterSensor, WaterSensor, String>.Context ctx, Collector<String> out) throws Exception {

                            }
                        }
                )

        wsDS.keyBy()
                .intervalJoin(wsDS.keyBy())
                .between()
                .process(
                        new ProcessJoinFunction<WaterSensor, T1, Object>() {
                            @Override
                            public void processElement(WaterSensor left, T1 right, ProcessJoinFunction<WaterSensor, T1, Object>.Context ctx, Collector<Object> out) throws Exception {

                            }
                        }
                )
         */
    }
}
